using System;
using System.Linq;
using Fluent.IO;
using TripleA.Core.Interfaces.Entities;

namespace TripleA.Core.Extensions.FileSystem
{
    /// <summary>
    /// This step will check that the specified folder has no items (files for folders)
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class IsFolderEmptyStep<T> : StepBase<T>
        where T: Context
    {
        private readonly string _folder;

        public IsFolderEmptyStep(string folder)
        {
            _folder = folder;
        }

        public override void Execute(T context)
        {
            var path = Path.Get(_folder);

            if (path.FileSystemEntries().Any())
                throw new ApplicationException(string.Format("Folder {0} is not empty", _folder));
        }
    }
}